-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: remove mypy ignore from pandas/core/construction.py #53112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TYP: remove mypy ignore from pandas/core/construction.py #53112
Conversation
# Incompatible types in assignment (expression has type "ndarray[Any, | ||
# dtype[Any]]", variable has type "MaskedArray[Any, Any]") | ||
data = data.astype(dtype, copy=True) # type: ignore[assignment] | ||
data = ma.asarray(data.astype(dtype, copy=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your PR - would it work to just rename data
? looks like the issue that it's getting reassigned to a different type
something like
data_newname = data.astype(dtype, copy=True)
data_newname.soften_mask()
data_newname[mask] = fill_value
return data_newname
else:
return data.copy()
(the hardest part would arguably be coming up with a good name, i.e. not data_newname
but something more descriptive, but I haven't looked at this carefully enough yet to think of what)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @MarcoGorelli for your comment. I will do, as you suggest. What do you think, could be sanitized_data
or sanitized_ma
a suitable new name for data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me, leaving open a bit in case others have comments
EDIT: oops, not green
Looks like mypy raises an error, I will fix it. |
I think the issue might be that Calling it, the return type is typed to be data = np.ma.MaskedArray([1,2,3], mask=[False, False, True])
reveal_type(data) # Revealed type is "numpy.ma.core.MaskedArray[Any, Any]"
reveal_type(data.astype('int64', copy=True)) # Revealed type is "numpy.ndarray[Any, numpy.dtype[Any]]" Might be worth checking if there's an issue in numpy about it, and if not, then reporting to them? Perhaps this could be made more precise on their end? The method which says "Convert the input to a masked array of the given data-type" is the one you'd originally used: |
This reverts commit 533d841.
Thanks, I'll check if there's an issue on GitHub about it.
I rolled back the commit to the first one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's get this in, thanks @natmokval
Related to #37715
mypy ignore[assignment] was removed from pandas/core/construction.py